package actions

import actions.commandsmap.BaseMapper
import actions.commandsmap.Mapper
import dsl.parameters.Parameter
import webdriver.groovydsl.WebDriverDsl

abstract class Action {
    static final String BASE_URL = "http://localhost:8080/GrailsWeb/"

    ActionType actionType
    List<Parameter> parameters
    String item
    Mapper mapper = new BaseMapper()

    abstract String getResultScript()

    protected String baseNavigationURL() {
        return BASE_URL + item
    }

    static String navigationCommand(String url) {
        return "navigate to:'${url}'\n"
    }

    static String typeCommand(String text, String fieldName, Boolean time=false) {
        if (time) {
            return "type '${text}', into:textField(named:'${fieldName}')\n"
        }
        return "type ${text}, into:textField(named:'${fieldName}')\n"
    }

    static String clickCommand(String buttonLabel) {
        "click button('${buttonLabel}')\n"
    }

    static String clickByClassCommand(String className) {
        "click buttonClass('${className}')\n"
    }

    static String pauseCommand(int time, String type = "seconds") {
        "after ${time}.${type}\n"
    }

    static String selectCommand(String itemLabel, String selectName) {
        "select ${itemLabel}, from:combobox(named:'${selectName}')\n"
    }

    static String checkContainsCommand(String text) {
        "page contains:text(${text})\n"
    }

}
